﻿using Microsoft.Phone.Info;
using Microsoft.Phone.Tasks;
using Q42.WinRT.Data;
using SpaceNeedle.SDK.Windows.Platform;
using SpaceNeedle.SDK.Windows.Platform.Commands;
using SpaceNeedle.SDK.Windows.Platform.Data;
using SpaceNeedle.x6473.WindowsPhone.Common;
using SpaceNeedle.x6473.WindowsPhone.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace SpaceNeedle.x6473.WindowsPhone.ViewModels
{
    public class ExtendedSplashScreenViewModel : GlobalViewModel
    {
        
        public ExtendedSplashScreenViewModel() : base()
        {
            
        }

        public AppContent.SplashInfo StaticContent
        {
            get { return this.Get<AppContent.SplashInfo>(); }
            set { this.Set(value); }
        }

        

        protected async override void Load()
        {
                this.IsInProgress = true;

                await this.ClearCacheAsync();

                await base.LoadAsync();

                await AppViewModel.Instance.LoadPhones();
                await AppViewModel.Instance.LoadRequests();

                App.CreatePushNotificationChannel();

                Byte[] userIdBytes = (Byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId");
                AppViewModel.Instance.Properties.DeviceId = Convert.ToBase64String(userIdBytes);

                this.StaticContent = this.AppContent.Splash;

                //await Task.Delay(TimeSpan.FromSeconds(5));

                if (AppViewModel.Instance.Properties.Me == null)
                {
                    AppServices.Current.NavigationService.NavigateDirect(ViewsUris.Welcome);
                }
                else
                {
                    AppServices.Current.NavigationService.NavigateDirect(ViewsUris.Home);
                }

                this.IsInProgress = false;

            this.OnLoaded();

            Tracking.SendView(ViewsNames.Splash);
        }
    }
}
